package com.wandian.texas.dao.Impl;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.wandian.texas.db.DBMgr;
import com.wandian.texas.db.WandianBaseDao;
import com.wandian.texas.entity.FriendsEntity;
import com.wandian.util.Log;

/**
 * @author long
 * @Create 2012-10-25 下午3:24:34
 * @QQ 108232706
 * @version 1.0
 * @description FriendsDaoImpl
 */
public class FriendsDaoImpl extends WandianBaseDao {

	public FriendsDaoImpl(DBMgr _dbMgr) {
		super(_dbMgr);
	}

	// @Override
	// protected Connection openConn() {
	// return this.dbMgr.getDbWandian();
	// }

	public List<FriendsEntity> getFriendList(int userId) {
		List<FriendsEntity> friends = new ArrayList<FriendsEntity>();
		String produceName = "sp_GetFriendList";
		CallableStatement stmt = null;
		this.dbMgr.lock.lock();
		this.dbMgr.setCurrentDb(DBMgr.TexasPokerDB);
		try {
			stmt = this.execProduce2(produceName, userId);
		} catch (Exception e) {
		} finally {
			this.dbMgr.lock.unlock();
		}
		ResultSet rs = null;
		int count = 0;
		if (stmt != null) {
			try {
				boolean hasResultSet = stmt.execute(); // 是否有结果集返回
				if (hasResultSet) {
					rs = stmt.getResultSet();
					FriendsEntity friend;
					while (rs.next()) {
						friend = new FriendsEntity();
						friend.UserId = rs.getInt("UserId");
						friend.Sex = rs.getInt("Sex");
						friend.NickName = rs.getString("NickName");
						friend.HeadImage = rs.getBytes("HeadImage");
						friend.Icon = rs.getString("icon");
						friend.IsPlaying = rs.getInt("IsPlaying");
						friend.CurrentRoomId = rs.getInt("CurrentRoomId");
						friend.Money = rs.getFloat("Money");
						friends.add(friend);
					}
				}
				/*
				 * else { while (stmt.getMoreResults()) { rs =
				 * stmt.getResultSet(); if (rs != null) { if (rs.last()) { count
				 * = rs.getInt("Count"); break; } } } }
				 */
			} catch (SQLException e) {
				count = 0;
				Log.error("执行出错" + produceName, e);
			} finally {
				closeConn(stmt, rs);
			}
		}
		return friends;
	}
}
